package it.unibo.imola.parser.evaluation.entity;

import java.util.ArrayList;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class InstructionSequence {
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	private GlobalEnvironment env = null;
	private ArrayList<Instruction> instructions = null;
	
	public InstructionSequence() {
		env = new GlobalEnvironment();
		instructions = new ArrayList<Instruction>(0);
	}

	public void exec() throws Exception {
		env.clear();
		for(Instruction i : instructions){
			i.exec(env);
		}		
	}
	
	public void addInstruction(Instruction i) throws Exception{
		if(i == null){
			throw new Exception("i == null");
		}
		if(!i.check(env)){
			throw new Exception("!i.check(env)");
		}
		instructions.add(i);
	}


	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this);
	}
}
